Wide-spectrum type system incorporating representation types, correctness types, coercions, and function overload resolution

ABSTRACT

In an embodiment of the invention, one or more tangible non-transitory computer-readable storage media may store the following instructions. Defining representation type spaces R 1  and R 2  and correctness type spaces C 1  and C 2  over the representation type spaces R 1  and R 2 , respectively. Defining a representation type space R and a correctness type space C over the representation type space R, such that a semilattice associated with the correctness type space C is a function semilattice over respective semilattices associated with the correctness type spaces C 1  and C 2 .

RELATED APPLICATIONS

This patent application claims the benefit of U.S. ProvisionalApplication No. 61/320,544, filed Apr. 2, 2010. Provisional ApplicationNo. 61/320,544 is hereby incorporated by reference in its entirety.

BACKGROUND

Many computer programming languages have a notion of type. The precisemeaning of this notion differs from language to language, but in mostcases, types are involved in at least two related aspects of thelanguage:

-   -   Types describe the representation of values. For example, the        type char might describe an 8-bit value, while double might        describe a 64-bit value.    -   Types are used to resolve overloads of at least some functions.        For example, + of two 32-bit integer values behaves differently        from + of two 32-bit floating point values.

In some programming languages, often called statically typed languages,types may play an additional role of providing certain correctnessguarantees: the computer programming language processing system mayreject certain programs as not type-correct. Other programming languagesare said to be dynamically typed. A few languages offer both astatically and a dynamically typed aspect.

BRIEF DESCRIPTION OF THE DRAWINGS

The accompanying drawings, which are incorporated in and constitute apart of this specification, illustrate one or more embodiments of theinvention and, together with the description, explain the invention. Inthe drawings,

FIG. 1 illustrates an example programming environment in an illustrativeembodiment;

FIG. 2 illustrates example numerical types connected by coercionrelationships in an illustrative embodiment;

FIG. 3 illustrates example coercions between real numerical types andcomplex numerical counterparts in an illustrative embodiment;

FIG. 4 illustrates example coercions between algebraic objects in anillustrative embodiment;

FIG. 5 illustrates an algebraic characterization of a universalsemilattice over a partially ordered set using a commutative diagram inan illustrative embodiment;

FIG. 6 illustrates an example flowchart describing acounter-example-to-canonical-form function performed in a programmingenvironment in an illustrative embodiment;

FIG. 7 illustrates an example flowchart describing an adjoin-elementfunction performed in a programming environment an illustrativeembodiment;

FIG. 8 illustrates an example flowchart describing a canonicalizefunction performed in a programming environment in an illustrativeembodiment;

FIG. 9 illustrates an example flowchart describing the process forcalculating the greatest lower bound performed in a programmingenvironment in an illustrative embodiment;

FIG. 10 illustrates an example flowchart describing the process for alattice operator less-than-or-equal-to performed in a programmingenvironment in an illustrative embodiment;

FIG. 11 illustrates an algebraic characterization of a universalfunction semilattice over a compliant map using a commutative diagram inan illustrative embodiment;

FIG. 12 illustrates an example flowchart describing the overloadresolution rule performed in a programming environment in anillustrative embodiment;

FIG. 13 illustrates an example flowchart describing the coercion offunction values performed in a programming environment in anillustrative embodiment;

FIGS. 14A, 14B, 14C, and 14D illustrate example software classdefinitions that may be configured to practice an illustrativeembodiment of the invention

FIG. 15 illustrates an example distributed environment that may beconfigured to practice an illustrative embodiment; and

FIG. 16 illustrates an example of a computer system that may beconfigured to practice an illustrative embodiment of the invention.

DETAILED DESCRIPTION Overview

One embodiment of the invention may relate to a particular type systemcalled a wide-spectrum type system, suitable for a computer programminglanguage that offers both statically and dynamically typed aspects.There exists an extensive literature on this subject, including Theoriesof Programming Languages by John C. Reynolds, published 1998 and 2009,which may provide the prerequisites for the material discussed here.

A fundamental property of a type is that it may describe, in one way oranother, a set of values. Throughout this document a type t has anassociated set of values V_(t). The set V_(t) may be infinite, but inany given computation, only a finite subset of V_(t) is used. Some typesystems may introduce a notion of a subtype, a relation on types thatmay say something about the relationship of the associated sets ofvalues. For example, if t₁ is a subtype of t₂, then V_(t) ₁ is a subsetof V_(t) ₂ . Another definition of subtype may state, for example, thatif t₁ is a subtype of t₂, then the programming language supplies acoercion from t₁ to t₂. A coercion may be implicitly introduced by theprogramming language implementation when, for example, a variable has avalue of type t₁ but a value of type t₂ is needed. For example, in the Cprogramming language the type single may be said to be a subtype of thetype double. If x has type single and the function ƒ takes one argumentof type double, then the construct ƒ(x) is type-correct, and animplementation of the C language automatically supplies an applicationof the coercion function that takes an argument of type single andproduces a result of type double. If t₁ is a subtype of t₂, for example,this document will use the notation γ_(t) ₂ _(,t) ₁ to denote thecoercion function from t₁ to t₂. Thus, the C programming language has arule that for the above f and x, the construct ƒ(x) is equivalent to theconstruct ƒ(γ_(double, single)(x)).

Example Programming Environment

FIG. 1 illustrates an example programming environment 100 in anillustrative embodiment. The programming environment 100 may includewide-spectrum type system module 110, type space module 120, functionsemilattices module 130, and function type space module 140.

Type space module 120 may include both representation types 150,correctness types 160, and coercions 155. Representation types 150 maycorrespond most closely to the traditional meaning of “type,” becausethey correspond to the representation of values.

A single element of the set of correctness types 160 may correspond tomany elements of the set of representation types 150. A correctness type160 may serve to unify different representations of the same underlyingdata semantics.

Coercions 155 may correspond to the traditional meaning of the term,referring to a function g implicitly applied to the argument of afunction ƒ, before calling ƒ For example, the language semantics may saythat for certain ƒ and x, ƒ(x) means ƒ(g(x)).

Function semilattices module 130 may correspond to predicates onfunction values. Function values form the basis of function types, andfunction values may also be used in the absence of types to analyzefunction behavior.

Function type space module 140 may provide the fundamental operations onfunction representation types. Function type space module 140 mayinclude function overload resolution 180, function coercion 170,function correctness types 175, and function representation types 185.

Function overload resolution 180 may provide the technique that decidesnot only which overload to call for a particular application of anoverloaded function, but also the application of coercions 155 thatalign the arguments of the call to those expected by the chosenoverload.

Function coercion 170 may refer to the coercion technique appliedspecifically to function values.

Function representation types 185 may refer to a set of representationtypes 150, each of whose elements is a representation type for afunction represented as a list of overloads.

Function correctness types 175 may refer to a set of correctness types160, each of whose elements corresponds to a set of mutually coerciblefunction representation types.

The wide-spectrum type system 110 may combine representation types 150,correctness types 160, and coercions 155 aspects and the operations onfunction representation types 185. Operations on function representationtypes 185 may include function overload resolution 180 and function typecoercion 170, and function correctness types 175. Function correctnesstypes 175 may include operators of function semilattices 130.

FIG. 2 illustrates example numerical types connected by coercions 155relationships 210, 220 in an illustrative embodiment. The coercions 155,for example, integer to rational 210 and double to single 220 are shown.Other coercions 155 of numerical types of higher and lower precision mayalso be similarly expressed. The direction of coercions 155 may follow,for example, the rule in the MATLAB® computer program from MathWorks,Inc., which coerces higher precision types to lower precision types.Reversing the direction of the vertical arcs, for example, may give therule from the C programming language that coerces a lower precision type(single) to a higher precision type (double). In an embodiment of theinvention, coercions 155 may be handled at the system level and notnecessarily by particular choices of coercions or of particular types.

FIG. 3 illustrates example coercions 155 between real types and complexcounterparts in an illustrative embodiment. As shown in FIG. 3, aninteger 310 may be coerced to either a value of type rational 320 orcomplex 330. For example, any type t where complex(t) is valid, theremay be a coercion taking a value x of type t to x+0√−1, a value of typecomplex(t). Thus, a real number may be considered to be a complexnumber, via another example of a coercion.

In one embodiment, a type denoted NEVER, about which the key fact isV_(NEVER)=0, (i.e., there are no values of this type) may be consideredas the only type with an empty set of values. Thus, there is a coercionfrom NEVER to any type t, namely the map with an empty domain. But, thismap may rarely be used because functions usually do not have NEVER as anargument type, as that results in never calling the function. On theother hand, a function may often have NEVER as a result type, because inpractice, an implemented function may never return. For example, thefunction may loop forever, it may throw control to an outer point suchas an error function, etc.

FIG. 4 illustrates example coercions 155 between some algebraic objectsin an illustrative embodiment. FIG. 4 illustrates coercions 155 betweentypes that in many languages may be called classes. Classes may beconsidered at a higher level than types of values. In this case,coerces-to corresponds to what an object-oriented language may callinherits from. FIG. 4 depicts the following objects OrderedField(p, t)410, Field(p, t) 420, Chain (t) 430, and EquivalenceDomain(t) 440.OrderedField(p, t) 410 may be a type constructor corresponding to themathematical definition of an ordered field.

OrderedField(p, t) 410 may take two parameters, namely a precision value(e.g., exact, approximate, etc) and a type (e.g., rational, single,double, etc.)

Field(p, t) 420 may be a type constructor corresponding to themathematical notion of a field. Field(p, t) 420 may take the sameparameters as OrderedField(p, t) 410. Mathematically, any ordered fieldmay also be a field.

Chain (t) 430 may be a type constructor corresponding to themathematical definition of a set X and a relation < that is a totalordering on X. Chain (t) 430 may take only a single parameter, namely atype.

EquivalenceDomain(t) 440 may be a type constructor corresponding to themathematical definition of an equivalence relation E on a set X when forall x, y, zεX, E has reflexivity (e.g., x E x), symmetry (e.g., x E y ifand only if y E x) and transitivity (e.g., if x E y and y E z, then x Ez). EquivalenceDomain(t) 440 may take a single parameter, namely a type.

EquivalenceDomain(t) 440 may be a base class to Field(p, t) 420 andChain (t) 430. In other words, Field(p, t) 420 and Chain (t) 430 may bederived (e.g., subclasses) from EquivalenceDomain(t) 440. Further,OrderedField(p, t) 410 may be derived from both Field(p, t) 420 andChain (t) 430.

OrderedField(p, t) 410 may be coerced to Field(p, t) 420 and/or Chain(t) 430. Field(p, t) 420 or Chain (t) 430 may be coerced toEquivalenceDomain(t) 440.

The types or classes are specific examples only and an embodiment of theinvention may be implemented at a lower level or higher level (e.g.,system) than individual classes. The notion that t₁ can be used as t₂may be analogous to the concept of inheritance used in object-orientedlanguages. For example, if a function has class t₂ as the type of aformal parameter, and if t₁ inherits from t₂, then an actual value ofclass t₁ may be supplied as an actual parameter to the function.

ILLUSTRATIVE EMBODIMENTS

In an embodiment of the invention, programming environment 100 maydistinguish between representation types 150 and correctness types 160.There may be a set of representation types 150. A set of representationtypes may be defined by the above-mentioned property that each of itselements describes a set of values. There is a relation onrepresentation types 150 that amounts to the subtype relation, in thatit may govern coercions 155. For example, given types t₁ and t₂, therelation may be denoted by t₁≦t₂, and the relation may be calledcoerces-to to emphasize that it may be cyclic (e.g., the sub in subtypemay connote acyclicity). For technical convenience, it may be statedthat NEVER<t for any representation type 150 t. Observe that this isconsistent with the earlier remark that there is a coercion from NEVERto t. It may be possible for distinct types t₁ and t₂ to satisfy t₁≦t₂and t₂≦t₁. This condition may be denoted by t₁≈t₂, and t₁ and t₂ may bereferred to as equivalent, reflecting the fact that ≈ is indeed anequivalence relation. If t₁≈t₂, then the coercion may be inverses of oneanother (i.e., the composition of γ_(t) ₁ _(,t) ₂ and γ_(t) ₂ _(,t) ₁ ,denoted γ_(t) ₁ _(,t) ₂ ∘γ_(t) ₂ _(,t) ₁ , may be the identity on V_(t)₁ and γ_(t) ₂ _(,t) ₁ ∘γ_(t) ₁ _(,t) ₂ may be the identity on V_(t) ₂ ).In other words, in a sequence of coercions 155 on types t₁≦t₂≦ . . .≦t_(k), where t_(k)=t₁, called a cycle of coercions, each coercion maybe a non-information-losing change of representation.

The behavior of coercions 155 on cycles may be a special case of a moregeneral rule about the coerces-to relation and its interaction withcoercions 155. It may be required that coerces-to be a quasi-ordering,meaning that, for example, (a) for any type t, t≦t (reflexivity) and (b)for types t₁, t₂, and t₃, if t₁≦t₂ and t₂≦t₃, then t₂≦t₃ (transitivity).The corresponding rules for function coercion 170 may be (a) for anytype t, γ_(t,t) is the identity function on V_(t) (a technicalconvenience), and (b) for types t₁, t₂, and t₃, if t₁≦t₂ and t₂≦t₃, thenγ_(t) ₃ _(,t) ₂ ∘γ_(t) ₂ _(,t) ₁ =γ_(t) ₂ _(,d) ₁ ∘γ_(t) ₃ _(,t) ₁ (thecomposition rule).

A representation type space, by definition, is a triple R, ≦, γ where Ris a set of representation types 150, ≦ is a quasi-ordering of R, and γis a function that maps a pair of types t₁, t₂, where t₁≦t₂, to afunction which we have called a coercion and denoted γ_(t) ₂ _(,t) ₁ ,which maps values of type t₁ to values of t₂.

The coerces-to relation on types may be visualized as a graph, one thatis potentially cyclic. By standard graph theory, the strongly connectedcomponents of this graph partition the types into equivalence classesover ≈, and by the above remarks, any pair of types in the sameequivalence class are mutually coercible. This permits a precisecharacterization of correctness types 160. For example, let R, ≦, γ be arepresentation type space, and let R/≈ denote the set of equivalenceclasses of ≈. To say that C, τ is a correctness type space over R, ≦, γmeans, by definition, that τ is a map from R onto C such that τt₁=τt₂ ifand only if t₁≈t₂. Thus, there is a 1-1 correspondence between T1≈ andT.

This innovative distinction between relatedness of representation types150 and correctness types 160 may serve the purposes both of thedynamically typed aspects of a language (when representation may be allthat matters) and statically typed aspects (because absence of typefaults may depend only on correctness types 160).

Correctness Types

The partitioning of a graph into strongly connected components induces arelation on the components. For example, imagine drawing an arc from onestrongly connected component to a second if there is an arc from anyelement of the first strongly connected component to any element of thesecond. The resulting graph on strongly connected components is acyclic.This graph-theoretic fact may say the following with regard tocorrectness types 160: for example, denoting the element-of relation byε, let t₁, t₂εT be any elements satisfying t₁≦t₂; then there may be anarc from the strongly connected component to which t₁ belongs to thestrongly connected component to which t₂ belongs. Because elements of Tare in 1-1 correspondence with the strongly connected components, an arcmay exist from τt₁ to τt₂, a relation that may be written with adifferent symbol, still suggestive of ordering: τt₁

τt₂; briefly, this relation on T may be defined by the rule that for T₁,T₂εT, T₁

T₂ holds if and only if there exists t₁, t₂εT such that t₁≦t₂ andτt₁=T_(i) for i=1 and 2. Applying this rule to NEVER, the fact thatNEVER≦t for all tεT means that τ(NEVER)

τt. Denotation of τ(NEVER) may be by ⊥, referred to as bottom. Since forevery TεT there may be some tεT with τt=T, it follows that ⊥

T for every TεT.

To understand intuitively what

means, suppose that a variable x has correctness type 160 T₁ and thatthe argument of f has correctness type 160 T₂, with T₁

T₂. Then, without knowing the representation type 150 of x or of theargument of ƒ, one may still conclude that the construct ƒ(x) istype-correct. The reasoning is as follows. From T₁

T₂, we know that there exists t₁, t₂εT such that t₁≦t₂ and τt₁=T_(i) fori=1 and 2. For example, let the representation type 150 of x be t′₁εT,so τt′₁=τt₁. By the definition of correctness types 160, t′₁≈t₁, and bythe definition of ≈, it follows that t′₁≦t₁. Similarly, let therepresentation type 150 of the argument of ƒ be t′₂εT, for example. Thent₂≦t′₂, with the same reasoning as before. Since t₁≦t₂, transitivitysays that t′₁≦t′₂. Thus ƒ(x) is type-correct, since x may be coerced tothe type required by ƒ, specifically, by γ_(t′) ₂ _(,t′) ₁ . So theintuitive meaning of

may be phrased as “can be used without type-fault as”.

With this intuitive understanding, the purely formal properties of

may be characterized. The properties of a quasi-ordering and thedefinition of

may guarantee that

is not merely a quasi-ordering,

is a partial ordering. As a partial ordering,

obeys the additional axiom of anti-symmetry: if T₁

T₂ and T₂

T₁, then T₁=T₂.

Overload Resolution

Many programming languages, for example C++, may allow distinct functiondefinitions to have the same name, provided that the argument types aredistinct. Each such function definition may be said to be an overload.If two overloads share the same name, then the language definitionspecifies, for an application of that function name, which overloadfunction application may actually call. The issue of how to resolveoverloads in the presence of coercions 155 has bedeviled languagedesign. For example, let ƒ₁ and ƒ₂ be overloads of the same name ƒ, andlet t_(i1) be the argument representation type 150 of ƒ_(i). Assume thatt₁₁≠t₂₁ and that ƒ₁ and ƒ₂ are the only overloads of ƒ. Consider theconstruct ƒ(x) where the type of x is t′. The overload that should becalled is not obvious. A possibility may be that τt₁₁=τt₂₁. For example,a language that uses an embodiment of this invention may specify that aspecific type is coerced to another specific type. However, in anembodiment of this invention may not need to provide specific type totype coercions 155.

In other words, an embodiment of the invention may be independent of theparticular choice of types and coercions 155 that may be used in anyparticular context. We may thus assume that τt_(i1)=T_(i1) for i=1 and2, and that T₁₁≠T₂₁. Define T′ to be τt′. An embodiment of thisinvention may specify that the answer of which overload functionapplication call depends only upon the correctness types 160 T₁₁, T₂₁,and T′. Suppose first that T′

T_(i1) for both i=1 and 2. Then x may not be coerced to either argumenttype, and the construct ƒ(x) may be said to have a type fault. If T′

T₁₁ and T′

T₁₂, then obviously ƒ(x) should call ƒ₁, and there may be a symmetriccase for when calling ƒ₂ is the only option. The interesting case iswhen T′

T_(i1) for both i=1 and 2. One possibility is that T₁₁, T₂₁ (i.e., T₁₁

T₂₁ and T₁₁≠T₂₁) In this case, it may be preferable to call ƒ₁. A moretechnical justification is provided later, but the intuitive idea may beto coerce to the nearest available argument type. If T′

T₁₁

T₂₁, then T₂₁ may be “farther” from T′ than T₁₁. Symmetrically, if T₂₁

T₁₁, then ƒ₂ may be called by function application. Otherwise, T₁₁, T₂₁may be unordered (by definition, meaning that T₁₁

T₂₁ and T₂₁

T₁₁) and it may not be clear what to do.

However, suppose the type system required the following:

-   -   For any T₁ and T₂, there exists a T₀ such that:        -   T₀            T₁ and T₀            T₂.        -   If T′₀            T₁ and T′₀            T₂, then T′₀            T₀.

By a well-known lattice theoretic result, T₀ is unique. T₀ may be calledthe greatest lower bound (glb) of T₁ and T₂, and may be denoted with anoperator that suggests intersection: T₁

T₂. A partial ordering for which glb exists is said to be asemilattice-ordering. While the programming languages C and C++ do nothave a notion of type glb, Java does have such a notion for some types.

Constraints on Overloads

Intersection and overloads of ƒ are described in this section. Since T′

T_(i1) for i=1 and 2, we may conclude that T′

T₁₁

T₂₁. Further, since T′≠⊥, we conclude that T₁₁

T₂₁≠⊥. If ƒ₁ and ƒ₂ are the only overloads of ƒ, then the set ofoverloads of ƒ may be said to be incomplete. Even before encountering anapplication of a function that does not have a natural overloadresolution, the programming language implementation may look at the twooverloads of ƒ, with unordered types having a non-⊥ intersection, andissue a warning or error informing the user that there should be anoverload whose correctness argument type T₀ satisfies T₁₁

T₂₁

T₀. By requiring such a property of overloads, subject to someextensions defined later, the programming language definition mayguarantee that if applications do not have a type-fault, then they canbe resolved. This may require that correctness types 160 have a glboperation.

A few purely lattice-theoretic facts follow. The above definition of Hguarantees that T₁

T₂ if and only if T₁=T₁

T₂. (To gain some intuition here, think of E as set inclusion and H asset intersection.) The definition of

also guarantees that

is idempotent (T

T=T), commutative (T₁

T₂=T₂

T₁), and associative ((T₁

T₂)

T₃=T₁

(T₂

T₃)). A semilattice, by definition, is a set together with a functionthat is idempotent, commutative, and associative. For example, considerany semilattice S, denoting its function by

. Define a relation on S, denoted

, by the rule that s₁

s₂ if and only if s₁

s₁

s₂. Then E is a partial ordering and

is its glb function. This fact will be useful, because it may providetwo ways of looking at the same thing.

Function Types

Function types may be defined as types whose associated sets of valuesact as functions. Most type systems, even that for C, have some notionof function types. Given representation types 150 t₁≠NEVER and t₂, onemay form the function representation type 150 from t₁ to t₂, whose setof values may be defined as the set of all functions taking an argumentof type t₁ and yielding a value of type t₂. For example, in C, witht₁=double and t₂=single, the function type is written single (*)(double). Here, the notation double←single is a function type for afunction that takes an argument of type single and yields a result oftype double, or generically, t₂←t₁ is a function type for a functionthat takes an argument of type t₁ and yields a result of type t₂.Underneath, in both C and the notation here, a function type may beviewed as including a pair of types. (The type system may be assumed tobe rich enough so that a single type can describe multiple arguments andresults.)

While the type system of C may be viewed as having an implicit coercionfrom single to double, the type system of C does not have any coercions155 of its function types. Suppose, for example, we have functionrepresentation types 185 t₂←t₁ and t′₂←t′₁. In an embodiment of theinvention, coercions 155 on function types may be defined to work asfollows.

The following addresses when is it true that (t₂←t₁)≦(t′₂←t′₁). Considerthe example function ƒ, which has type t₁ as its argument type and t₂ asits result type. More succinctly, ƒ has representation type 150 t₂←t₁.Let g be another function whose argument type is t′₂←t′₁.

The following addresses when the construct g(ƒ) may be type-correct.Consider what g may do with its argument. For example, g may call theargument on a value of type t′₁. By definition, such a value would be atype-correct argument to ƒ when t′₁≦t₁. Similarly, consider what g doeswith the result of calling its argument ƒ. For example, g may use theresult of the call in a context expecting a value of type t′₂. Thiswould be type-correct as long as t₂≦t′₂. Thus:

-   -   (t₂←t₁)≦(t′₂←t′₁) if and only if t₂≦t′₂ and t′₁≦t₁

The following addresses the coerced value that may be passed to g. Basedon the above discussion, the coerced value would be: γ_(t′) ₂ _(,t) ₂∘ƒ∘γ_(t) ₁ _(,t′) ₁ . In other words, γ_(t′) ₂ _(←t′) ₁ _(,t) ₂ _(←t) ₁may be defined by the rule:γ_(t′) ₂ _(←t′) ₁ _(,t) ₂ _(←t) ₁ (ƒ)=γ_(t′) ₂ _(,t) ₂ ∘ƒ∘γ_(t) ₁ _(,t′)₁

Note that the coercions 155 on the result types are in the samedirection as that of the function types (it may be said to becovariant), but the coercion on the argument types is in the oppositedirection from that on the function types (it may be said to becontravariant).

Intersection of Function Types

In an embodiment of the invention, correctness types 160 may likewiseapply to everything previously mentioned above regarding representationtypes 150:

-   -   Given correctness types 160 T₁≠⊥ and T₂, T₂←T, is a correctness        function type.    -   Given correctness types 160 T₁, T₂, T′₁, and T′₂, with T₁≠⊥T′₁:        -   (T₂←T₁)            (T′₂←T′₁) if and only if T₂            T′₂ and T′₁            T₁

The following addresses (T₁₂←T₁₁)

(T₂₂←T₂₁), given T_(i2)←T_(i1) for i=1 and 2. Because of contravariance,T₁₂

T₂₂←T₁₁

T₂₁ may not provide a greatest lower bound for the ordering

on function types. The presence of contravariance might tempt one torequire that the semilattice of correctness types 160 be a lattice, soit would have a union-like operator ␣. With a union-like operator U, asuitable proposed definition of the above intersection may be T₁₂

T₂₂←(T₁₁␣T₂₁). This may fix the contravariance problem with greatestlower bound, but it is incorrect for semantic reasons. (Briefly, theproblem is that while H always corresponds to logical conjunction, thereare useful lattices in which U does not correspond to logicaldisjunction, so the use of U in the proposed definition may not belogically sound.)

In sum, for example, let T₁ and T₂ be sets of correctness types 160.These may be the same sets, T₁ may be viewed as possible argument types,and T₂ may be viewed as possible result types. As proposed, a candidateset of function types from T₁ to T₂ may be defined by F₀(T₁,T₂)=T₂×(T₁−⊥), where the following two facts may be observed:

-   -   There exists a partial ordering on F₀(T₁, T₂) that is        contravariant on the T₁ component and covariant on the T₂        component.    -   F₀(T₁, T₂) may not be semilattice-ordered even with additional        constraints on T₁.

A key to getting past the impasse of F₀(T₁, T₂) not beingsemilattice-ordered even with additional constraints on T₁ may be toinject F₀(T₁, T₂) into a larger set, which may be denoted by F(T₁, T₂).A function may be defined on this set which may make it a semilattice.The function may be denoted by

, and the related partial ordering may be denoted by

. A key property:

-   -   Let τ be the injection from F₀(T₁, T₂) to F(T₁, T₂). Then for        T₂←T₁ and T′₂←T′₁ in F₀(T₁, T₂):        -   (T₂←T₁)            (T′₂←T′₁) if and only if τ(T₂←T₁)            τ(T′₂←T′₁)

Intuitively, F(T₁, T₂) has a copy of F₀(T₁, T₂) inside F(T₁, T₂), withthe same ordering.

The construction of F(T₁, T₂) is described in detail below. Theconstruction may require several steps:

-   -   Use the partial ordering F₀(T₁, T₂) to construct a semilattice,        denoted F₁(T₁, T₂).    -   F₁(T₁, T₂) may turn out to be too big for the set of function        types, in that it may have different elements whose role as        types may be identical. A particular equivalence relation ≈ may        be defined on F₁(T₁, T₂) that takes into account these        equivalences. The set of partitions of this equivalence        relation, denoted F₁(T₁, T₂)/≈, is also a semilattice.    -   Providing an algorithm to compute the canonical form for        elements of F₁(T₁, T₂)/≈. By definition, F(T₁, T₂) is the set of        these canonical forms. Thus F(T₁, T₂) is isomorphic to F₁(T₁,        T₂)/≈. The algorithm for canonical form may lead directly to an        algorithm for computing        and indirectly to an algorithm for        on F(T₁, T₂). These algorithms may provide a practical        implementation of function types.        Intersection of Function Types, Step 1

A universal semilattice over a partially ordered set P may be described,whose ordering may be denoted by

. A subset of P may be defined to be unordered if each pair of elementsis unordered. The set of elements for the semilattice may be given by:

-   -   S={p        P|p is finite, non-empty, and unordered}

Let p={p₁, . . . , p_(k)}, where p may represent the symbolic expressionp₁

. . .

p_(k).

-   -   Given p        P, define the minimal elements of p, abbreviated mnl(p), to be        {pεp|∃/p′εp with p′        p}.    -   Given p₁, p₂εS, by definition p₁        p₂=mnl(p₁∩p₂).    -   For example, let p_(i)={p_(i)} for i=1 and 2, where p₁        p₂. Then p₁    -   p₂ reduces to        -   mnl({p₁}∪{p₂})=mnl({p₁, p₂})={p₁}‘=’p₁

This represents the symbolic equation p₁

p₂=p₁ when p₁

p₂.

S and

form a semilattice. The partial ordering associated with thissemilattice has the following algorithmic characterization:

-   -   p₁        p₂ if and only if for all p₂εp₂, there exists p₁εp₁ such that p₁        p₂.

There may be a natural way of injecting P into S, namely:

-   -   The map from P to S is given by defining τ(p) to be {p}. It        satisfies:        Equation one:        p ₁        p ₂ if and only if τ(p ₁)        (p ₂)  (1)

FIG. 5 illustrates the algebraic characterization of a universalsemilattice over a partially ordered set, using a mathematical techniqueknown as a commutative diagram in an illustrative embodiment. Themeaning of universal in this context is that if S′ 550 is any othersemilattice such that there is an injection τ′ 560 from P 510 to S′550satisfying equation one (1) but with τ′ 560 rather than τ520, then thereexists a unique map h 440 from S 530 to S′ 550 such that:

-   -   h(s₁        s₂)=h(s₁)        h(s₂)    -   t′=h∘t

F(T₁, T₂) may be obtained by applying the above construction to thepartially ordered set F₀(T₁, T₂) to create, for example, a semilattice.

Questions may arise such as to what do the elements of F₁(T₁, T₂) meanas correctness types 160 and what is the underlying set ofrepresentation types 150 that some τ maps to F₁(T₁, T₂). For example,suppose that T₁₁, T₂₁εT₁ are unordered and non-⊥, and let T₁₂, T₂₂εT₂ bearbitrary. Then T₁₂←T₁₁ and T₂₂←T₂₁ are unordered, and:Equation two:{T ₁₂ ←T ₁₁ ,T ₂₂ ←T ₂₁ }εF ₁(T ₁ ,T ₂)  (2)

For i=1 and 2, let ƒ_(i) be an overload of the function ƒ, and supposethat these are the only overloads of ƒ. Let the correctness type 160 ofƒ_(i) be T_(i2)←T_(i1), and suppose that T₁₁

T₂₁=⊥, so this is a valid set of overloads. Since T_(i1)≠⊥ and T₁₁

T₂₁=⊥, it follows that T₁₁, T₂₁ are unordered, so equation two (2)holds. This suggests what {T₁₂←T₁₁, T₂₂←T₂₁} means as a correctness type160: it is the type of the overall function ƒ. For example:

-   -   It is valid to call ƒ on a value whose correctness type 160 is        T₁₁, and in this case, the result has correctness type 160 T₁₂;        and    -   it is valid to call ƒ on a value whose correctness type 160 is        T₂₁, and in this case, the result has correctness type 160 T₂₂.        The C and C++ programming languages do not have function types        of this kind.

The representation types 150 corresponding to the correctness types 160of F₁(T₁, T₂) may be understood by asking what function values looklike. In the case where function ƒ consists of overloads ƒ₁ and ƒ₂, avalue representing ƒ includes two pointers, one to ƒ₁ and one to ƒ₂. Animplemented representation of such value would commit to the order inwhich ƒ₁ and ƒ₂ appear in the value. So, for t_(ij) such thatτt_(ij)=T_(ij), here are some possible representation types 150 thatcorrespond to {T₁₂←T₁₁, T₂₂←T₂₁}

-   -   <T₁₂←T₁₁, T₂₂←T₂₁> (describes the pair ƒ₁, ƒ₂)    -   <T₂₂←T₂₁, T₁₂←T₁₁> (describes the pair ƒ₂,ƒ₁)

Note that such values may be passed as arguments and results,incorporated into data structures, etc.

Intersection of Function Types Step 2

With this understanding of function representation types 150 and theircorresponding values, we turn to the previous statement that F₁(T₁, T₂)is too big. The technical statement behind this remark may be thatcorrectness function types should characterize an overall function. Forreasons detailed below, F₁(T₁, T₂) may be constructed so that thefollowing equality holds whenever T₁₁

T₂₁≠⊥:Equation three:(T ₁₂ ←T ₁₁)

(T ₂₂ ←T ₂₁)=(T ₁₂ ←T ₁₁)

(T ₂₂ ←T ₂₁)

((T ₁₂ ←T ₂₂)←(T ₁₁ ≦T ₂₁))  (3)

To explain why equation three (3) should hold, suppose, for example,that the function g takes a function argument ƒ and that g has two callsites off, the i^(th) site having an argument whose correctness type 160is T_(i1) and requires that the result has correctness type 160 T_(i2).Let T be the correctness type 160 of ƒ. Since ƒ can be used at call sitei, it may be plausible that where the correctness type 160 iseffectively T_(i2)←T_(i1), that ƒ is coercible to a value of this type,i.e., that T

T_(i2)←T_(i1) for i=1 and 2. In a semilattice, this is equivalent to:Equation four:T

(T ₁₂ ←T ₁₁)

(T ₂₂ ←T ₂₁)  (4)

Conversely, if T obeys this inequality, then the type-correctness of thecall sites in g may be guaranteed. Given that T is the type of ƒ,equation four (4) may be the condition for the type-correctness of theconstruct g(ƒ), under the assumption that the type of the argument of gis (T₁₂←T₁₁)

(T₂₂←T₂₁).

Suppose that a function ƒ has overloads for i=1 and 2, and that ƒ_(i)has correctness type 160 T_(i2)←T_(i1). Since T₁₁

T₂₁≠⊥, ƒ should also have a third overload, whose correctness argumenttype is T₁₁

T₂₁. Let the correctness result type of this overload be T₀₂, so theoverload has correctness function type T₀₂←T₁₁

T₂₁. Since this overload of ƒ may be called at either site of theargument of g, type-correctness requires T₀₂

T_(i2), for i=1 and 2, or equivalently, T₀₂

T₁₂

T₂₂. This may be formalized by strengthening the constraint on overloadsto include this rule on the result type, but weakening the constraint onthe argument type:

-   -   If there are overloads of the same function with correctness        types 160 T_(i2)←T_(i1) for i=1 and 2, and if T₁₁        T₂₁≠⊥, then there must be an overload of the function with        argument type T₀₁ such that T₁₁        T₂₁        T₀₁ and result type T₀₂ such that T₀₂        T₁₂        T₂₂.

Given the above, consider a function h which has two call sites of itsargument with the same characteristics as those of g, but also has athird call site of its argument with correctness argument type T₁₁

T₂₁ and correctness result type T₁₂

T₂₂. As with g, the correctness argument type of g is:Equation five:(T ₁₂ ←T ₁₁)

(T ₂₂ ←T ₂₁)

((T ₁₂

T ₂₂)←(T ₁₁

T ₂₁))  (5)

Then ƒ is also a type-correct argument to h. Thus, any type-correctargument to g may be a type-correct argument to h. The converse holds (ghas a subset of the call site characteristics of those of h). As such,the intersection type in equation five (5) and the right-hand side ofequation four (4) are the same. This equality is what explains equationthree (3).

Intersection of Function Types, Step 3

Mathematically, F(T₁, T₂) may be defined to be F₁(T₁, T₂) modulo theequivalence relation given by equation three (3). It is not clear apriori that such a semilattice exists. An algorithmic construction ofsuch a semilattice may be used to imply the existence of such asemilattice. A step in the construction of the semilattice may be analgorithm for computing the canonical representation of elements. Forexample:

-   -   Let pεF₁(T₁, T₂), and let <T_(i2), T_(i1)>εp for i=1 and 2, and        define p′ to be p−<T₁₂, T₁₁>−<T₂₂, T₂₁>. Then by the        construction of F₁(T₁, T₂):        p=p′        (T ₁₂ ←T ₁₁)        (T ₂₂ ←T ₂₁)    -   Suppose T₁₁        T₂₁≠⊥. Then by equation three (3):        p=p′(T ₁₂ ←T ₁₁)        (T ₂₂ ←T ₂₁)        ((T ₁₂        T ₂₂)←(T ₁₁        T ₂₁))    -   Undoing the liberties with notation and using the algorithm for        in F₁(T₁, T₂):        p≈mnl(p′∪{<T ₁₂ ,T ₁₁ >,<T ₂₂ ,T ₂₁ >,<T ₁₂        T ₂₂ ,T ₁₁        T ₂₁>})=mnl(p+<T ₁₂        T ₂₂ ,T ₁₁        T ₂₁>)

It may be possible for the final set here to be exactly the same as S,and if this is so for every possible pair <T_(i2), T_(i1)>εS, then S issaid to be in function semilattice canonical form. More algorithmically,we use the next definition, which then leads to a definition of F(T₁,T₂):

-   -   pεF₁(T₁, T₂) is said to be in canonical form when for every pair        of elements <T_(i2), T_(i1)> in p, for i=1 and 2, either T₁₁        T₂₁=—or there exists <T₂, T₁>εp such that T₂←T₁        (T₁₂        T₂₂)←(T₁₁        T₂₁).    -   By definition, F(T₁, T₂)={pεF₁(T₁, T₂)|p is in canonical form}.

An algorithm to compute the canonical form, called the functionsemilattice reduction algorithm follows:

-   -   canonicalize(pεF₁(T₁, T₂))→F(T₁, T₂)    -   While <T_(i2), T_(i1)> for i=1 and 2 is a counter-example to        canonical form: —Set p to mnl(p+<T₁₂        T₂₂, T₁₁        T₂₁>).    -   Return p as the final result.

FIG. 6 illustrates an example flowchart 600 describing a counter exampleto canonical form performed in programming environment 100 in anillustrative embodiment. In block 620, execution of thecounter-example-to-canonical-form function may begin. Thecounter-example-to-canonical-form function may accept p as a parameterand may return no-counter-example-found or a pair of elements.

In block 630, a pair of elements of p may be examined. If all theelements of p have been examined, the function may returnno-counter-example-found and flow may end at 690. If a pair of elementsof p remains to be examined, flow may continue.

In block 640, the pair of elements to be examined may be defined as<T₁₂, T₁₁>, <T₂₂, T₂₁>. T₁ may be defined as T₁₁

T₂₁.

In block 650, a check may be performed to determine whether T₁ is equalto the bottom element ⊥, then flow may move back to 630. If T₁ is notequal to the bottom element ⊥, then flow may continue.

In block 660, T₂ may be defined as T₁₂

T₂₂.

In block 670, a check may be performed to determine whether a <T′₂, T′₁>exists in p such that T′₂

T₂ and T₁

T′₁, if so, then flow may move back to 630. If a <T′₂, T′₁> does notexist in p such that T′₂

T₂ and T₁

T′₁, then flow may continue.

In block 680, the function may return <T₂, T₁> and flow may move to 690and end.

It may be proved that (a) this algorithm always terminates, and (b) thefinal result is independent of arbitrary choices made for <T_(i2),T_(i1)>. Neither fact is obvious, and the proofs are omitted herebecause the proofs are not necessary to practice an embodiment of theinvention.

FIG. 7 illustrates an example flowchart 700 describing an adjoin-elementfunction performed in programming environment 100 in an illustrativeembodiment. In block 720, execution of the adjoin-element function maybegin. The adjoin-element function may accept p and a pair of elementsas parameters and may return a modified p.

In block 730, p may be examined. A check may be performed to determinedwhether all of the elements in p have been examined, if so then <T₂, T₁>may be added to p and the modified p may be returned and flow may moveto 770 and end. If not all of the elements in p have been examined, thena pair of elements may be selected and flow may continue.

In block 740, the selected pair of elements may be defined as <T′₂,T′I>.

In block 750, a check may be performed to determine whether T₂

T′₂ and T′₁

T₁, if so, remove <T′₂, T′₁> from p.

In block 760, flow may move back to 730.

FIG. 8 illustrates an example flowchart describing canonicalize functionperformed in programming environment 100 in an illustrative embodiment.In block 820, execution of the canonicalize function may begin. Thecanonicalize function may accept p as a parameter and may return amodified p.

In block 830, x may be the result of callingcounter-example-to-canonical-form 600 with p as a parameter.

In block 840, x may be examined. A check may be performed to determinewhether x is equal to no-counter-example-found, if so, then p should bereturned and flow may move to 890 and end. If x is not equal tono-counter-example-found then flow may continue.

In block 850, the value x may have the form <T₂, T₁>. The value p may beset equal to adjoin-element 600 with the parameters p and <T₂, T₁>.

In block 860, flow may move to 830.

The definition of F(T₁, T₂) makes it clear that F(T₁, T₂)

F₁(T₁, T₂). The semilattice operation defined in F₁(T₁, T₂) by

₁ and its partial ordering may be denoted by

₁. This notation may be used in the implementation of the semilatticeand associated partial ordering on F₁(T₁, T₂), using

and

. The algorithms for the semilattice (all p_(i)εF(T₁, T₂)):

takes (p₁, p₂) as arguments and returns p₀ as a result:

-   -   Return canonicalize(p₁        ₁p₂).

takes (p₁, p₂) and returns false or true as a result

-   -   Return p₁        p₂.

FIG. 9 illustrates an example flowchart 900 describing the process forgreatest lower bound

performed in programming environment 100 in an illustrative embodiment.In block 920, execution of the H function may begin. The

function may accept p₁ and p₂ as parameters and return p₀.

In block 930, the value p₀ may be defined as mnl(p₁∪p₂). Based on thediscussion above, p₁

₁p₂=mnl(p₁∪p₂).

In block 940, p₀ may be defined to be canonicalize(p₀) as in FIG. 8.

In block 950, p₀ may be returned and flow may end at 960.

FIG. 10 illustrates an example flowchart 1000 describing the process fora lattice operator less-than-or-equal-to

function performed in programming environment 100 in an illustrativeembodiment. In block 1020, execution of the

function may begin. The

function may accept p₁ and p₂ as parameters and return either true orfalse.

In block 1030, p₂ may be examined. A check may be performed todetermined whether all elements of p₂ have been examined, if so, thenthe function may return true, and flow may move to 1070 and end. If notall elements of p₂ have been examined, then an element from p₂ may beselected that has not yet been examined and flow may continue.

In block 1040, the selected element of p₂ may be defined as <T₂₂, T₂₁>.

In block 1050, p₁ may be examined. A check may be performed to determinewhether there is no element <T₁₂, T₁₁> such that T₁₂

T₂₂ and T₂₁

T₁₁, if so, then return false, and flow may move to 1070 and end. Ifthere is an element <T₁₂, T₁₁> such that T₁₂

T₂₂ and T₂₁

T₁₁, then flow may continue.

In block 1060, flow may move back to 1030.

The idempotency and commutativity of H follow from the same propertiesof

₁, but the following are not obvious (and the proofs are omitted):

-   -   is associative and is the glb for        .    -   coincides with        ₁ on F(T₁, T₂).    -   For all p₁, p₂εF(T₁, T₂):        -   canonicalize(p₁            ₁p₂)=canonicalize(p₁)            canonicalize(p₂)

Another (and also non-obvious and not proved here) property of thisconstruction requires a preliminary definition.

-   -   Let S be any lattice, and let κ be a map from F₀(T₁, T₂) to S.        For clarity, the operator and ordering on S may be denoted as        _(s) and        _(s). Viewing F₀(T₁, T₂) as a partially ordered set in the usual        way, κ may be referred to as compliant (i.e., with equation        three (3)) when it satisfies these conditions:        -   If <T₁₂, T₁₁>            <T₂₂, T₂₁>, then κ(T₁₁, T₁₂)            _(s)κ(T₂₁, T₂₂).        -   For all <T_(i2), T_(i1)>εF₀(T₁, T₂), for i=1 and 2, with T₁₁            ₁T₁₂≠⊥:            -   κ(T₁₁, T₁₂)                _(s)κ(T₂₁, T₂₂)=κ(T₁₁, T₁₂)                κ(T₂₁, T₂₂)                _(s)κ(T₁₂                ₂T₂₂, T₁₁                ₁T₁₂)    -   Define κ_(F) from F₀(T₁, T₂) to F(T₁, T₂) by κ(T₁, T₂)={<T₂,        T₁>}. Then κ_(F) is compliant, and if S is any semilattice and        there is a compliant κ from F₀(T₁, T₂) to S, then there exists a        unique h such that:        -   For all p₁, p₂εF(T₁, T₂), h(p₁            p₂)=h(p₁)            _(s)h(p₂).        -   κ=h∘κ_(F).

FIG. 11 illustrates an algebraic characterization of a universalfunction semilattice over a compliant map using a mathematical techniqueknown as a commutative diagram. FIG. 11 includes semilattices F₀(T₁, T₂)1110 and F(T₁, T₂) 1140, semilattice S 1160, and maps h 1150, κ 1130 andκ_(F) 1120. The meaning of universal in this context is that if S 1160is any other semilattice such that there is an injection κ 1130 fromF₀(T₁, T₂) 1110 to S 1160 instead of κ_(F) 1120 from F₀(T₁, T₂) 1110 toF(T₁, T₂) 1140, then there exists a unique map h 1150 from F(T₁, T₂)1140 to S 1160 such that:

-   -   For all p₁, p₂εF(T₁, T₂), h(p₁        p₂)=h(p₁)        _(s)h(p₂)    -   κ=h∘κ_(F)        By definition, a function semilattice 130 over a pair of        semilattices T₁, T₂ is a set S′ that is in 1-1 correspondence        with F(T₁, T₂), and which thus supports a function from F₀(T₁,        T₂) that is equivalent to κ_(F), and a glb operations that is        equivalent to glb on F(T₁, T₂).        Intersection of Function Types Summary

In an embodiment of the invention, start with two sets of representationtypes 150 T₁ and T₂, and associated coercions 155, as described above.Also as described above, obtain sets of correctness types 160 T₁ and T₂.Initial consideration of overload resolution 180 may lead to requiringthat the T_(i) may be semilattice-ordered. Denote the intersectionoperator on T_(i) by

_(i). The ability to always and unambiguously chose an overload toinvoke when there is no apparent type-fault may lead to requirementsthat the set of overloads must obey certain constraints related to

₁. These constraints may then lead to a definition of a set ofcorrectness types 160 F(T₁, T₂) and a semilattice operation on them,which may be denoted

. This construction may describe function types from T₁ to T₂.

In another embodiment of the invention, the partially ordered set thatcorresponds to the above semilattice is isomorphic to the set ofequivalence classes of a certain quasi-ordering whose elements may beviewed as representation types 150 of functions from T₁ to T₂, whereeach function value is represented by a list of overloads, and wherecoercion is defined by composition of overloads with coercion of theargument (before the call on the overload) and of the result (after thecall on the overload).

Using the Canonical Form of Correctness Types to Reformulate theConstraint on Overload Arguments

The above description introduced the use of the intersection of types toaddress overload resolution. The above description also suggested aconstraint on the correctness types 160 of overload arguments to avoidtype-faults, provided only that the types of the overload argument typescover the type of an argument at a call site. Because this constraintmay use the intersection of types and because it may be desirable tohave an overload resolution rule that works for all functions, includingthose with function arguments, the type system of this invention definesthe intersection of function types. This culminates in the constructionof a particular semilattice given semilattices for correctness argumenttypes and result types. An element of this construction is a canonicalform for elements of the semilattice.

In another embodiment of the invention, the canonical form ofcorrectness types 160 may be used to reformulate the constraint onoverload arguments. This constraint may have an advantage that incertain circumstances, for example, it may reduce the number ofoverloads that must be defined. However, one consequence is that theconstraint may align the behavior of the correctness type 160 of theoverall function with the representation types 150 of the overloads. Assuch, analysis based on the correctness types 160 of functions reflectswhat happens in the overloads.

The constraints assume a function ƒ with overloads ƒ₁, . . . , ƒ_(k),k>0, where ƒ has the function representation type 150 t_(i2)←t_(I1),i.e., the argument representation type 150 is t_(i1) (t_(i1)≠NEVER) andthe result representation type 150 is t_(i2). For convenience, T_(ij)may be defined to be τt_(ij), for i=1, . . . , k and j=1 or 2. Theconstraints, with suggestive names:

-   -   Argument Representation Type Distinctness If i₁≠i₂, then τt_(i)        ₁ _(,1)≠t_(i) ₂ _(,1). In other words, the set {<t_(i2),        t_(i1)>}_(i=1, . . . , k) has distinct second components.    -   Argument Correctness Type Distinctness If t_(i) ₁ _(,1)=t_(i) ₂        _(,1), then t_(i) ₁ _(,2)=t_(i) ₂ _(,2). In other words, the set        {<t_(i2), t_(i1)>}_(i=1, . . . , k) has distinct second        components.    -   No Missing Overloads If t_(i) ₁ _(,1), t_(i) ₂ _(,1) are        unordered and t_(i) ₁ _(,1)        t_(i) ₂ _(,1)≠⊥, then there exists i such that t_(i) ₁ _(,1)        t_(i) ₂ _(,1)        t_(i1) and t_(i2)        t_(i) ₁ _(,2)        t_(i) ₂ _(,2).    -   Consistent Coercibility If t_(i) ₁ _(,1)        t_(i) ₂ _(,1), then t_(i) ₁ _(,2)        t_(i) ₂ _(,2).

In another embodiment of the invention, define T_(ƒ) to be mnl{<T_(i2),T_(i1)>}_(i=1, . . . k). From the definition of F₁(T₁, T₂) as havingelements that are unordered sets, it follows that T_(ƒ)εF₁(T₁, T₂). Lessobviously, if the above constraints are met, then T_(ƒ)εF(T₁, T₂). Inother words, T_(ƒ) is in canonical form, or thatcanonicalize(T_(ƒ))=T_(ƒ). Thus, T_(ƒ) is the correctness type 160 of f.Choosing a representation type 150 of ƒ involves picking an order forthe overloads. If that order is 1, . . . , k, then t_(ƒ)=<<t₁₂, t₁₁>, .. . , <t_(k2), t_(k1)>> is the representation type 150. This leads to:

-   -   Given sets of representation types 150 T_(i) and maps τ_(i) to        sets of correctness types 160 T_(i), for i=1 and 2, a non-empty        sequence <<t_(i2), t_(i1)>>_(i=1, . . . , k) may be defined to        be an admissible function representation type 185 when it obeys        the constraints on overloads (which are stated, after all, using        only T_(i), τ_(i), T₁).    -   With the same notation, the set of function representation types        150 from T₁, τ₁, T₁ to T₂, τ₂, T₂ is by definition:        -   F={tε(F₀(T₁, T₂))^(k)|k>0, τ is admissible}            The notation F suppresses the dependence on T_(i), τ_(i),            T_(i).    -   The map τ from F to F(T₁, T₂) is given by:        -   τ(<<t_(i2), t_(i1)>>_(i=1, . . . , k))=mnl{<τ₂t_(i2),            τ₁t_(i1)>>_(i=1, . . . , k)}

By the above remarks, the range of τ is indeed F(T₁, T₂).

In defining quasi-ordering on F, the definition may use thequasi-ordering ≦_(i) defined on T_(i):

-   -   <<t_(1,i,2), t_(1,i,1)>>_(i=1, . . . , k) ₂ ≦<<t_(2,i,2),        t_(2,i,1)>>_(i=1, . . . , k) ₁ if and only if for every i₂ ε{1,        . . . , k₂}, there exists i₁ε{1, . . . , k₁} such that:        -   t_(1,i) _(l) _(,2)≦₂t_(2,i) ₂ _(,2) and t_(2,i) ₂            _(,1)≦₁t_(1,i) ₁ _(,1)

Omitted are the proofs that ≦ is a quasi-ordering and that τt₁=τt₂ ifand only if t₁≈t₂. To complete the definition of F, γ_(t) ₂ _(,t) ₁ mayneed to be defined when t₁≦t₂. That definition may use a techniquedeveloped in the next section.

Note, a consequence of consistent coercibility may be that picking thenearest available overloads avoids, if possible, type-faults in nestedapplications. For example, in ƒ(g(x)), if the nearest overload of g maybe chosen for the invocation at x, then the result of g(x) may be themost coercible, (smallest in

) that is possible. Making any other choice might cause an unnecessarytype-fault at the invocation of ƒ.

Overload Resolution Rule

Another embodiment of the invention may include an overload resolutionrule, which uses the fact that sets of overloads obey the constraints ofthe previous section. For example, suppose there is a function ƒ withrepresentation type 150 t_(θ), as above. In the call ƒ(x), let x haverepresentation type 150 t. Here is a function that produces either theindex i where ƒ_(i) is the function to invoke, or else a value referredto as type-fault, meaning that x is not a type-correct argument of ƒ:

-   -   overload-resolution-rule(t_(ƒ) a function representation type        185, t a representation type 150)→i or type-fault        -   Let T_(ƒ) be τt_(ƒ), i.e., the correctness function type            corresponding to t_(ƒ).        -   Let T be τt, i.e., the correctness function type            corresponding to t.        -   Let E be the set {<T₂, T₁>εT_(ƒ)|T            T₁}. These are the set of eligible overloads, i.e., those            whose arguments types do not rule out being called.        -   If E=Ø, then return type-fault. Otherwise, continue with the            following steps.        -   Define R=mnl{T₂|<T₂, T₁>εE}. It is not obvious, but it is            nevertheless the case that R has a single element, which we            will denote T_(result).        -   For convenience in the next step, let t_(ƒ)=<<t_(i2),            t_(i1)>>_(i=1, . . . , k).        -   Define A=mnl{τt₁|τt_(i2)=T_(result) for some i=1, . . . ,            k}. Like R, A has a single element, which we will denote            T_(argument).        -   The result i will satisfy the equations τt_(i1)=T_(argument)            and τt_(i2)=T_(result). The set of such indices is            non-empty, and in practice usually includes one element. In            the case of more than one such i, the final choice is made            on the basis of the relationship between t and t_(i1).        -   Return i.

Note that the representation type 150 of the result of ƒ(x) may dependupon the choice of i (if indeed there is a choice), but that thecorrectness type 160 is T_(result), which is independent of i.

FIG. 12 illustrates an example flowchart 1200 describing the overloadresolution rule performed in a programming environment 100 in anillustrative embodiment. In block 1220, execution may begin by callingthe overload-resolution-rule function. The overload-resolution-rulefunction may accept two parameters t_(ƒ), a function representation type185 of function ƒ, and t, a representation type 150 of an argument tofunction ƒ. The overload-resolution-rule function may return either i ora type-fault. Returning index i indicates that ƒ, is the function toinvoke. Returning a type-fault indicates that there is not arepresentation type 150 t that is a type-correct argument to function ƒ.

In block 1230, T_(ƒ) may be τt_(ƒ).

In block 1240, T may be τt.

In block 1250, E may be the set of eligible overloads (i.e., those whosearguments types do not rule out being called) defined as {<T₂,T₁>εT_(ƒ)|T

T₁}.

In block 1260, E may be examined. A check may be performed to determinewhether E=Ø, if so, return type-fault and flow may move to 1295 and end.If E≠Ø, flow may continue.

In block 1270, R may be defined as R=mnl{T₂|<T₂, T₁>εE}. It is notobvious, but it is nevertheless the case that R has a single element,which is denoted T_(result).

In block 1280, A may be defined as A=mnl{T₁|<T_(result), T₁>εE}. Like Rin 1270, A has a single element, denoted T_(argument).

In block 1290, the result may be an index i such thatT_(i1)=T_(argument) and T_(i2)=T_(result). This set is non-empty, and inpractice usually includes one element. In the case of more than one suchi, the final choice is made on the basis of the relationship between tand t_(i1).

In block 1295, the value i may be returned and the function may end at1299.

For t₁, t₂εF with t₁≦t₂, the definition of the function coercion 170algorithm, denoted γ_(t) ₂ _(,t) ₁ uses the overload resolution rule180. Recall that the definition of ≦ says that for all i₂ε{1, . . . ,k₂} there exists i₁ε{1, . . . , k} such that t_(1,i) ₁ _(,2)≦₂t_(2,i) ₂_(,2) and t_(2,i) ₂ _(,1)≦₁t_(1,i) ₁ _(,1). By the overload resolutionrule, if there exists an i₁, then the overload resolution picks aparticular one, given by i₁=r(i₂). Thus, when t_(h)=<<t_(hi2),t_(hi1)>>_(i=1, . . . , k) _(h) for h=1 and 2, and t₁≦t₂, define, forany ƒ=<ƒ₁, . . . , f_(k) ₁ >εV_(t) ₁ :γ_(t) ₂ _(,t) ₁ (ƒ)=<<γ_(t) _(2,i,2) _(,t) _(1,r(i),2) ∘ƒ_(r(i))∘γ_(t)_(1,r(i),1) _(,t) _(2i1) >>_(i=1, . . . ,k) ₂This equation, abstracted over ƒ, defines γ_(t) ₂ _(,t) ₁ .

FIG. 13 illustrates an example flowchart 1300 describing the coercions155 of function values performed in a programming environment in anillustrative embodiment. In block 1220, execution may begin by callingthe coerces-to function. The coerces-to function may accept twoparameters, t₁ and t₂, both are function representation types 150. Thecoerces-to function may return γ, representing a function, which whengiven a function ƒ₁, represented as a list of overloads, and having arepresentation type 150 t₁, yields a function ƒ₂, again represented as alist of overloads, and having a representation type 150 t₁. Thus ƒ₂ isthe coercion of ƒ₁ to type t₂. The values t₁ and t₂ exist in F andt₁≦t₂.

In block 1330, t_(j) may be defined as <<t_(j,i,2),t_(j,i,i)>>_(i=1 . . . , k) _(j) . Initially, γ₁, . . . , γ_(k) ₂ areundefined. The i₂ ^(th) step of the algorithm defines γ_(i) ₂ .

In block 1340, the value i₂ may be examined. A check may be performed todetermine whether all values of i₂ in the range 1, . . . , k₂ have beenconsidered, if so, then γ₁, . . . , γ_(k) ₂ are all defined, and returnγ=<γ₁, . . . , γ_(k) ₂ > and flow may move to 1390 and end. Otherwise,examine i₂ where γ_(i) ₂ is not yet defined and flow may continue.

In block 1350, the overload-resolution-rule(t₁, t_(2,i) ₂ _(,1)), as inFIG. 12, may be called. Because t₁≦t₂, the result is not type-fault, sothe result will be it in the range 1, . . . , k₁. For convenience,define t′_(jk) to be t_(j, i) _(j) ₁ for j, k=1, 2. It is guaranteedthat t′₂₁≦t′₁₁ and t′₁₂≦t′₂₂.

In block 1360, coerces-to may be used on the constituent type spaces(perhaps recursively). The value γ′₂ may be defined by coerces-to(t′₁₂,t′₂₂) and γ′₁ by coerces-to(t′₂₁, t′₁₁).

In block 1370, the value γ_(i) ₂ may be defined by the abstraction overƒ of γ′₂∘f∘γ′₁. Flow may move back to 1340.

Illustrative Embodiment Summary

One embodiment of the invention may include a type system with thefollowing features:

-   -   Representation types 150, viewed as elements of a quasi-ordering        in which t₁≦t₂ may mean that a value of type t₁ is implicitly        coercible 155 to a value of type t₂.    -   Correctness types 160, viewed as elements of a partial-ordering        that may be isomorphic to the set of equivalence classes of        representation types 150, where the equivalence relation is        defined by t₁≈t₂ if and only if t₁≦t₂ and t₂≦t₁.

Another embodiment may include the above with the following features:

-   -   The partial ordering on correctness types 160 may be a        semi-lattice ordering. The greatest lower bound operator is        denoted by        .

The partial ordering may have a bottom element denoted by ⊥.

-   -   Given correctness types 160 T₁≠⊥ and T₂, there is a type        representing a set of functions with argument correctness type        160 T₁ and result correctness type 160 T₂. This type may be        denoted as T₂←T₁.    -   Given correctness types 160 T_(i1)≠⊥ and T_(i2), for i=1 and 2,        the        and ← operators may be related by the following equation, which        holds whenever T₁₁        T₂₁≠⊥:    -   (T₁₂←T₁₁)        (T₂₂←T₂₁)=(T₁₂←T₁₁)        (T₂₂←T₂₁)        ((T₁₂        T₂₂)←(T₁₁        T₂₁))    -   The canonical form for a correctness type 160 may be a set p of        pairs of types, subject to these constraints:        -   The second component of a pair is not ⊥. As such, a pair            <T₂, T₁> as representing a function type T₂←T₁.        -   If <T_(i2), T_(i1)> are elements of p, for i=1 and 2, and if            T₁₁            T₂₁≠⊥, then there exists <T₂, T₁>εp such that:            -   T₁₁                T₂₁                T₁ and T₂                T₁₂                T₂₂

Another embodiment may include the above with the following features:

-   -   Functions may be overloaded, where the argument and result        representation types 150 of the set of overloads may be subject        to the constraints as described in the third illustrative        embodiment section.    -   Function representation types 150 may be lists of pairs of        representation types 150, subject to these same constraints.

Another embodiment may include the above with the following features:

-   -   The resolution algorithm as described above may be given a        representation type 150 t and a function representation type        150 p. The result of the algorithm may be either the indication        that t is not matched by any element of p or an index saying        which element of p is the best match for t.    -   The resolution algorithm may be used in the overload resolution        algorithm and in the algorithm for coercing one function type to        another.        Example Software Implementation

FIGS. 14A, 14B, 14C, and 14D illustrate example software classdefinitions that may be configured to practice an illustrativeembodiment of the invention.

OrderedSetWithBottom class 1405 may be a base class with a definitioncommon to a partially ordered set and a quasi ordered set.

QuasiOrderedSet class 1410 may subclass OrderedSetWithBottom class 1405and may implement a quasi-ordered set.

PartiallyOrderedSet class 1415 may subclass OrderedSetWithBottom class1405 and may implement a partially ordered set.

Semilattice class 1420 may subclass PartiallyOrderedSet class 1415 andmay implement a semilattice. Semilattice class 1420 may have only oneclass definition, that of a parameterized class Semilattice. Concretesubclasses of the Semilattice class 1420 (an example may be seen inclass 1430) may need to define the glb (corresponds to H) and is_bottommethods, for example.

RepresentationTypeSpace class 1425 may be a subclass of QuasiOrderedSetclass 1410 and may implement a representation type 150. Concretesubclasses of the RepresentationTypeSpace class 1425 (an example may beseen in 1460) may need to define gamma (corresponds to γ).

CorrectnessTypeSpace class 1430 may subclass RepresentationTypeSpaceclass 1425 and Semilattice class 1420. CorrectnessTypeSpace class 1430may implement correctness types 160. The tau method of this classrepresents the connection τ between representation and correctness types160.

ResultArgumentPair class 1435 may be a generic class for pairs typed byresult and argument classes.

RepresentationParameterFunction class 1440 may provide a generic meansof defining a class for lists of pairs associated with arguments andresults. Two examples of its use, with different template parameters,may be seen in class 1460.

BottomFunction class 1445 defines the bottom of a quasi-ordered set forfunctions.

OrderedSetWithBottomFunction class 1450 may subclassOrderedSetWithBottom class 1405. OrderedSetWithBottomFunction class 1450may define “le” for the quasi-ordered set of function representationtypes 150. In an illustrative embodiment, OrderedSetWithBottomFunctionclass 1450, may be used to implement the

function as illustrated in FIG. 10.

QuasiOrderedSetFunction class 1455 may subclass QuasiOrderedSet class1310 and OrderedSetWithBottomFunction class 1450.QuasiOrderedSetFunction class 1455 may enhance the definition of thequasi-ordered set of function representation types 150 by definingequality.

RepresentationTypeSpaceFunction class 1460 may subclassRepresentationTypeSpace class 1425. RepresentationTypeSpaceFunctionclass 1460 may define gamma (coercion) for function representation types150.

CorrectnessParameterFunction class 1465 may provide a generic means ofdefining a class for sets of pairs associated with arguments andresults. Two examples of its use, with different template parameters,are in class 1475.

SemilatticeFunction class 1470 may subclass Semilattice class 1420. Inan illustrative embodiment, software code, SemilatticeFunction class1470, may be used to implement the

function as illustrated in FIG. 9.

CorrectnessTypeSpaceFunction class 1475 may subclassCorrectnessTypeSpace class 1430, RepresentationTypeSpaceFunction class1460, and SemilatticeFunction class 1470. CorrectnessTypeSpaceFunctionclass 1475 may define τ.

The CorrectnessParameterFunction class 1465 may be parameterized by theclass of the argument type and class of a function type. TheCorrectnessParameterFunction class 1465, may be a list of pairs, whichrepresents the set of pairs discussed above. Other embodiments mayinclude other representations of sets of pairs.

The CorrectnessTypeSpaceFunction class 1475 constructor may take twoCorrectnessTypeSpace objects, corresponding to arguments and results.These objects become fields of the resultingCorrectnessTypeSpaceFunction object (note thatCorrectnessTypeSpaceFunction may be derived from CorrectnessTypeSpace).This type may be also the type defined by CorrectnessTypeSpaceFunction,and this type may be obtained by CorrectnessTypeSpaceFunction < . .. >.T. This type may be the argument/result type of the meet method andthe argument type of the is_bottom method. Note that these methods areonly declared, not defined.

Class definitions 1405-1475 represent example software code. Classdefinitions 1405-1475 (i.e., example software code) may be stored intangible non-transitory computer readable storage media.

Other embodiments may include additional classes. In other embodiments,classes may be combined as needed. Class definitions 1405-1475 arewritten in the C++ programming language, but similar implementations maybe written in other types of programming languages such as, but notlimited to, the MATLAB® language, C, Fortran, Forth, ADA, Pascal,JavaScript, Python, C#, Java, Visual Basic, the Mathlab language, etc.

Example Distributed System

FIG. 15 illustrates a distributed environment 1500 that may beconfigured to practice an illustrative embodiment. Referring to FIG. 15,environment 1500 may include a client 1510, network 1540, serviceprovider 1550, target environment 1560 and cluster 1570. Note that thedistributed environment illustrated in FIG. 15 is just one example of adistributed environment that may be used. Other distributed environmentsmay include additional devices, fewer devices, or devices inarrangements that differ from the arrangement of environment 1500. Forexample, distributed environment 1500 can be implemented as a computingcloud if desired.

Client 1510 may include a device capable of sending and/or receivinginformation (e.g., data) to and/or from another device, such as targetenvironment 1560. Information may include any type of machine-readableinformation having substantially any format that may be adapted for use,e.g., in one or more networks and/or with one or more devices. Theinformation may include digital information and/or analog information.The information may further be packetized and/or non-packetized. In anembodiment, client 1510 may download data and/or code via network 1540.For example, client 1510 can download code for a wide-spectrum typesystem 110 consistent with aspects of the invention.

Client 1510, service provider 1550, and/or target environment 1560 mayimplement programming environment 100.

Client 1510 may be, for example, a desktop computer, a laptop computer,a client computer, a server computer, a mainframe computer, a personaldigital assistant (PDA), a web-enabled cellular telephone, a smartphone, smart sensor/actuator, or another computation or communicationdevice that executes instructions that enable the device to perform oneor more activities and/or generate one or more results.

In an embodiment, client 1510 may include a technical computingenvironment (TCE) 1520, graphical modeling software 1530 and analysissoftware 1535. In other embodiments, client 1510 may include othercomponents, applications, etc. Embodiments of TCE 1520 may containcomputer-executable instructions (e.g., code) and data that areconfigured to implement the TCE. The instructions may includeinstructions configured to implement modeling software 1520 and/orgraphical analysis software 1535. An example embodiment of the currentinvention may be implemented in a TCE 1510. An example embodiment of oneor more of function semilattices 130, correctness types 160,representation types 150, function overload resolution 180, functioncoercion 170, and/or a wide-spectrum type system 110 provided byprogramming environment 100 may be implemented in a TCE 1520.

Modeling software 1530 and the analysis software 1535 may be graphical,textual or a hybrid that includes both textual and graphicalcapabilities/features. Modeling software 1530 may includecomputer-executable instructions that allow, e.g., a user to buildand/or execute a model. For example, modeling software 1530 may allow auser to build and execute a time-based model, a state-based model, anevent-based model, a dataflow-based model, etc. An example embodiment ofthe current invention may be implemented as part of modeling software1530.

Analysis software 1535 may include computer-executable instructions thatallow information in a model to be evaluated. Evaluating a model mayinclude generating tests for the model that satisfy model coverageobjectives, user-defined objectives, etc. In addition, evaluating amodel may include proving various model properties and generatingexamples of violations of these properties. Moreover, evaluating a modelmay include analyzing the model, in accordance with techniques describedherein. In an illustrative embodiment, analysis software 1535 mayinclude the Simulink® Design Verifier software which is available fromMathWorks, Inc. An example embodiment of the current invention may beimplemented as part of analysis software 1535.

Network 1540 may include any network capable of exchanging informationbetween entities associated with the network, including, for example,client 1510, service provider 1550, target environment 1560 and cluster1570. Exchanged information may include, for example, packet data and/ornon-packet data. Implementations of network 1540 may include local areanetworks (LANs), metropolitan area networks (MANs), wide-area networks(WANs), etc. Information may be exchanged between entities using anynetwork protocol, such as, but not limited to, the Internet Protocol(IP), Asynchronous Transfer Mode (ATM), Synchronous Optical Network(SONET), the User Datagram Protocol (UDP), Institute of Electrical andElectronics Engineers (IEEE) 802.11, etc.

Network 1540 may include various network devices, such as, for example,routers, switches, firewalls, servers, etc. Portions of network 1540 maybe wired (e.g., using wired conductors, optical fibers, etc.) and/orwireless (e.g., free-space optical (FSO), radio frequency (RF), acoustictransmission paths, etc.). Portions of network 1540 may include asubstantially open public network, such as the Internet. Portions ofnetwork 1540 may include a more restricted network, such as a virtualprivate network (VPN). It should be noted that implementations ofnetworks and/or devices operating on networks described herein are notlimited with regards to information carried by the networks, protocolsused in the networks, the architecture/configuration of the networks,etc.

Service provider 1550 may include code (e.g., software), logic (e.g.,hardware or a combination of hardware and software), etc., that makes aservice available to another device in distributed environment 1500.Service provider 1550 may include a server operated by an entity (e.g.,an individual, a corporation, an educational institution, a governmentagency, etc.) that provides one or more services to a destination, suchas client 1510. The services may include software containingcomputer-executable instructions that may be executed, in whole or inpart, by a destination, by service provider 1550 on behalf of thedestination, or some combination thereof. An example embodiment of thecurrent invention may be implemented as part of service provider 1550.

For example, in an embodiment, service provider 1550 may provide one ormore subscription-based services to various customers via network 1540.These services may be accessed by the customer (e.g., via client 1510).Service provider 1550 may limit access to certain services based on,e.g., a customer service agreement between the customer and serviceprovider 1550. The service agreement may allow the customer to accessservices that allow the customer to build and/or execute a model. Inaddition, the service agreement may allow the customer to furtheranalyze models, generate code from the models, generate various reports,access audit services that allow a customer's code to be audited, etc.The service agreement may include other types of arrangements, such ascertain fee-based arrangements or restricted access arrangements. Forexample, a customer may pay a fee which provides the customer unlimitedaccess to a given package of services for a given time period (e.g.,hourly, daily, monthly, yearly, etc.). For services not included in thepackage, the customer may have to pay an additional fee in order toaccess the services. Still other arrangements may be resource-usagebased. For example, the customer may be assessed a fee based on anamount of computing resources used, network bandwidth used, etc.

Target environment 1560 may include a device that receives informationfrom client 1510, service provider 1550, or cluster 1570. For example,target environment 1560 may receive executable code from client 1510,where the executable code allows target environment to perform anoperation when the code is executed. Client 1510 may have generated theexecutable code using TCE 1520, graphical modeling software 1530, and/ora code generator (not shown in FIG. 15).

Cluster 1570 may include a number of processing resources that performprocessing on behalf of another device, such as client 1510, serviceprovider 1550 and/or target environment 1560. Cluster 1570 may includelogic that manages and/or coordinates the operation of multipleprocessing resources. For example, cluster 1570 may send data to and/orreceive results from these processing resources. In an embodiment,cluster 1570 may include units of execution (UEs) 1580 a, b, c, and d(collectively UEs 1580) that may perform processing on behalf of client1510 and/or another device, such as service provider 1550. An exampleembodiment of the current invention may be implemented on one or moreUEs 1580.

UEs 1580 may include hardware, software, or hybrid logic that performsprocessing operations on behalf of TCE 1520. For example, in anembodiment UEs 1580 may parallel process portions of a graphical modelcreated by user of client 1510. This parallel processing may includeperforming analysis on the model, parsing the model into portions,and/or aggregating results from respective UEs 1580 into a single resultfor display to a user at client 1510. UEs 1580 may reside on a singledevice or chip or on multiple devices or chips. For example, UEs 1580may be implemented in a single application specific integrated circuit(ASIC) or in multiple ASICs. Likewise, UEs 1580 can be implemented in asingle computer system using virtualization techniques. Other examplesof UEs 1580 may include field programmable gate arrays (FPGAs), complexprogrammable logic devices (CPLDs), application specific instruction-setprocessors (ASIPs), microprocessors, etc.

Illustrative Computing Architecture Example System

FIG. 16 illustrates an example of a computer system 1600 that may beconfigured to practice an embodiment of the invention. For example,computer system 1600 may be used to implement client 1510, serviceprovider 1550, target environment 1560, programming environment 100,etc. Computer system 1600 may include processor 1620, memory 1670,storage device 1640, input device 1610, output device 1660, and networkinterface 1680. Processor 1620 may include logic configured to executecomputer-executable instructions that implement embodiments of theinvention. An example of a processor that may be used with the inventionincludes the Pentium® processor, Core i7® processor, or Xeon® processorall available from Intel Corporation, Santa, Clara, Calif. Theinstructions may reside in memory 1670 and may include instructionsassociated with TCE 1520.

Memory 1670 may be a computer-readable medium that may be configured tostore instructions configured to implement embodiments of the invention.Memory 1670 may be a primary storage accessible to processor 1620 andcan include a random-access memory (RAM) that may include RAM devices,such as, for example, Dynamic RAM (DRAM) devices, flash memory devices,Static RAM (SRAM) devices, etc. Storage device 1640 may include amagnetic disk and/or optical disk and its corresponding drive forstoring information and/or instructions. Memory 1670 and/or storagedevice 1640 may store class definitions 1405-1475.

Interconnect 1650 may include logic that operatively couples componentsof computer system 1600 together. For example, interconnect 1650 mayallow components to communicate with each other, may provide power tocomponents of computer system 1600, etc. In an embodiment of computersystem 1600, interconnect 1650 may be implemented as a bus.

Input device 1610 may include logic configured to receive informationfor computer system 1600 from, e.g., a user. Embodiments of input device1610 may include keyboards, touch sensitive displays, biometric sensingdevices, computer mice, trackballs, pen-based point devices, etc. Outputdevice 1660 may include logic configured to output information fromcomputer system. Embodiments of output device 1660 may include cathoderay tubes (CRTs), plasma displays, light-emitting diode (LED) displays,liquid crystal displays (LCDs), printers, vacuum florescent displays(VFDs), surface-conduction electron-emitter displays (SEDs), fieldemission displays (FEDs), etc.

Network interface 1680 may include logic configured to interfacecomputer system 1600 with a network, e.g., network 1540, and may enablecomputer system 1600 to exchange information with other entitiesconnected to the network, such as, for example, service provider 1550,target environment 1560 and cluster 1570. Network interface 1680 may beimplemented as a built-in network adapter, network interface card (NIC),Personal Computer Memory Card International Association (PCMCIA) networkcard, card bus network adapter, wireless network adapter, UniversalSerial Bus (USB) network adapter, modem or any other device suitable forinterfacing computer system 1600 to any type of network.

It should be noted that embodiments may be implemented using somecombination of hardware and/or software. It should be further noted thata computer-readable medium that includes computer-executableinstructions for execution in a processor may be configured to storeembodiments of the invention. The computer-readable medium may includevolatile memories, non-volatile memories, flash memories, removablediscs, non-removable discs and so on. In addition, it should be notedthat various electromagnetic signals such as wireless signals,electrical signals carried over a wire, optical signals carried overoptical fiber and the like may be encoded to carry computer-executableinstructions and/or computer data on e.g., a communication network foran embodiment of the invention.

A hardware unit of execution may include a device (e.g., a hardwareresource) that performs and/or participates in parallel programmingactivities. For example, a hardware unit of execution may perform and/orparticipate in parallel programming activities in response to a requestand/or a task it has received (e.g., received directly or via a proxy).A hardware unit of execution may perform and/or participate insubstantially any type of parallel programming (e.g., task, data, streamprocessing, etc.) using one or more devices. For example, in oneimplementation, a hardware unit of execution may include a singleprocessing device that includes multiple cores, and in anotherimplementation, the hardware unit of execution may include a number ofprocessors 1620. A hardware unit of execution may also be a programmabledevice, such as a field programmable gate array (FPGA), an applicationspecific integrated circuit (ASIC), a digital signal processor (DSP),etc. Devices used in a hardware unit of execution may be arranged insubstantially any configuration (or topology), such as a grid, ring,star, etc. A hardware unit of execution may support one or more threads(or processes) when performing processing operations.

A software unit of execution may include a software resource (e.g., atechnical computing environment [e.g., MATLAB® software], a worker, alab, etc.) that performs and/or participates in parallel programmingactivities. For example, a software unit of execution may perform and/orparticipate in parallel programming activities in response to receipt ofa program and/or one or more portions of the program. In an embodiment,a software unit of execution may perform and/or participate insubstantially any type of parallel programming using one or morehardware units of execution. Embodiments of a software unit of executionmay support one or more threads and/or processes when performingprocessing operations.

A TCE 1520 may include hardware and/or software based logic thatprovides a computing environment that allows users to perform tasksrelated to disciplines, such as, but not limited to, mathematics,science, engineering, medicine, business, etc., more efficiently than ifthe tasks were performed in another type of computing environment, suchas an environment that required the user to develop code in aconventional programming language, such as C++, C, Fortran, Pascal, etc.Example software code 1400 may be complied and processed by processor1620 and implemented in TCE 1520.

In one implementation, the TCE 1520 may include a dynamically typedlanguage that can be used to express problems and/or solutions inmathematical notations familiar to those of skill in the relevant arts.For example, the TCE 1520 may use an array as a basic element, where thearray may not require dimensioning. These arrays may be used to supportarray programming in that operations can apply to an entire set ofvalues, such as values in an array. Array programming may allow arraybased operations to be treated as a high-level programming technique ormodel that lets a programmer think and operate on whole aggregations ofdata without having to resort to explicit loops of individual non-array,i.e., scalar operations.

A TCE 1520 may further be adapted to perform matrix and/or vectorformulations that can be used for data analysis, data visualization,application development, simulation, modeling, algorithm development,etc. These matrix and/or vector formulations may be used in many areas,such as statistics, finance, image processing, signal processing,control design, life sciences, education, discrete event analysis and/ordesign, state based analysis and/or design, etc.

A TCE 1520 may further provide mathematical functions and/or graphicaltools (e.g., for creating plots, surfaces, images, volumetricrepresentations, etc.). In one implementation, the TCE 1520 may providethese functions and/or tools using toolboxes (e.g., toolboxes for signalprocessing, image processing, data plotting, parallel processing,optimization, etc.). In another implementation, the TCE 1520 may providethese functions as block sets (e.g., an optimization block set). Instill another implementation, the TCE 1520 may provide these functionsin another way, such as via a library, etc. The TCE 1520 may beimplemented as a text based environment, a graphically basedenvironment, or another type of environment, such as a hybridenvironment that is both text and graphically based.

ALTERNATIVE EMBODIMENTS

An alternative embodiment may implement a TCE 1520 using one or moretext-based products. For example, a text-based TCE 1520, may beimplemented using products such as, but not limited to, MATLAB® byMathWorks, Inc.; Octave; Python; Comsol Script; MATRIXx from NationalInstruments; Mathematica from Wolfram Research, Inc.; Mathcad fromMathsoft Engineering & Education Inc.; Maple from Maplesoft; Extend fromImagine That Inc.; Scilab from The French Institution for Research inComputer Science and Control (INRIA); Virtuoso from Cadence; or Modelicaor Dymola from Dynasim.

Other embodiments may implement a TCE 1520 in a graphically-based TCE1520 using products such as, but not limited to, Simulink®, Stateflow®,SimEvents™, etc., by MathWorks, Inc.; VisSim by Visual Solutions;LabView® by National Instruments; Dymola by Dynasim; SoftWIRE byMeasurement Computing; WiT by DALSA Coreco; VEE Pro or SystemVue byAgilent; Vision Program Manager from PPT Vision; Khoros from KhoralResearch; Gedae by Gedae, Inc.; Scicos from (INRIA); Virtuoso fromCadence; Rational Rose from IBM; Rhopsody or Tau from Telelogic; Ptolemyfrom the University of California at Berkeley; or aspects of a UnifiedModeling Language (UML) or SysML environment.

Another alternative embodiment may be implemented in a language that iscompatible with a product that includes a TCE 1520, such as one or moreof the above identified text-based or graphically-based TCE's 1520. Forexample, MATLAB® (a text-based TCE 1520) may use a first command torepresent an array of data and a second command to transpose the array.Another product, that may or may not include a TCE 1520, may beMATLAB®-compatible and may be able to use the array command, the arraytranspose command, or other MATLAB® commands. For example, the otherproduct may use the MATLAB® commands to suggest proper identifiers whenan unknown identifier is presented.

Yet another alternative embodiment may be implemented in a hybrid TCE1520 that combines features of a text-based and graphically-based TCE1520. In one implementation, one TCE 1520 may operate on top of theother TCE 1520. For example, a text-based TCE 1520 (e.g., MATLAB®) mayoperate as a foundation and a graphically-based TCE 1520 (e.g.,Simulink) may operate on top of MATLAB® and may take advantage oftext-based features (e.g., commands) to provide a user with a graphicaluser interface and graphical outputs (e.g., graphical displays for data,dashboards, etc.).

CONCLUSION

Implementations may provide devices and techniques that implement awide-spectrum type system, suitable for a programming language thatoffers both statically and dynamically typed aspects. An implementationmay include representation types 150 and correctness types 160 asdescribed herein. Another implementation may include function overloadresolution 180.

The foregoing description of example embodiments of the inventionprovides illustration and description, but is not intended to beexhaustive or to limit the invention to the precise form disclosed.Modifications and variations are possible in light of the aboveteachings or may be acquired from practice of the invention. Forexample, while a series of acts has been described with regard to FIGS.6-10 and 12-13 the order of the acts may be modified in otherimplementations consistent with the principles of the invention.Further, non-dependent acts may be performed in parallel.

In addition, implementations consistent with principles of the inventioncan be implemented using devices and configurations other than thoseillustrated in the figures and described in the specification withoutdeparting from the spirit of the invention. Devices and/or componentsmay be added and/or removed from the implementations of FIGS. 15 and 16.depending on specific deployments and/or applications. Further,disclosed implementations may not be limited to any specific combinationof hardware.

Further, certain portions of the invention may be implemented as “logic”that performs one or more functions. This logic may include hardware,such as hardwired logic, an application-specific integrated circuit, afield programmable gate array, a microprocessor, software, wetware, or acombination of hardware and software.

No element, act, or instruction used in the description of the inventionshould be construed as critical or essential to the invention unlessexplicitly described as such. Also, as used herein, the article “a” isintended to include one or more items. Where only one item is intended,the term “one” or similar language is used. Further, the phrase “basedon,” as used herein is intended to mean “based, at least in part, on”unless explicitly stated otherwise.

Headings and/or subheadings used herein are used to segment this patentapplication into portions to facilitate the readability of theapplication. These headings and/or subheadings are not intended todefine or limit the scope of the invention disclosed and/or claimed inthis patent application.

The scope of the invention is defined by the claims and theirequivalents.

What is claimed is:
 1. One or more tangible non-transitorycomputer-readable storage media for storing computer-executableinstructions executable by processing logic, the media storing one ormore instructions for: constructing semilattices S₁ and S₂ in aprogramming environment by a computer, where S₁ has bottom elementdenoted ⊥₁; determining a set S₀ of elements constructed from sets ofelements associated with the semilattices S₁ and S₂ in the programmingenvironment by the computer; determining a partial ordering, denoted

, on elements of the set S₀ in the programming environment by thecomputer; determining a greatest lower bound operation, denoted

, on the set S₀, consistent with

, in the programming environment by the computer; determining a map,denoted ←, taking as arguments an element of the semilattice S₁ otherthan ⊥₁ and an element of the semilattice S₂, and yielding an element ofS₀, in the programming environment by the computer, where ← isanti-isotonic on the element of S₁ and isotonic on the element of S₂, aneffect of ← on s₁ an element of S₁ and s₂ an element of S₂ denoted bys₂←s₁; determining, in the programming environment by the computer, afunction semilattice S over the semilattices S₁ and S₂, where Scomprises the function ← from S₁×S₂ to S₀ and a semilattice withconstituents S₀,

, and

; and constructing a representation for elements of the functionsemilattice S over the semilattices S₁ and S₂, each element s of Sincluding a set of pairs {<s_(i2),s_(i1)>}_(i=1, . . . , k), k being thesize of element s and each s_(ij) being an element of S_(j) for i=1, . .. , k and j=1 or 2, the set of pairs being in a function semilatticecanonical form.
 2. The one or more tangible non-transitorycomputer-readable storage media of claim 1, further comprisinginstructions for: determining a second set of pairs {<s′_(i2),s′_(i1)>}_(i=1, . . . , k), each s′_(ij) being an element of S_(j) fori=1, . . . , k and j=1 or 2, to be in the function semilattice canonicalform as equivalent to the condition that for all i₁ and i₂ in a rangefrom 1 to k, either s′_(i) ₁ _(,i)

s′_(i) ₂ _(,1)=⊥ or there exists i₀ in the range from 1 to k such thats′_(i) ₀ _(,2)

s′_(i) ₁ _(,2)

s′_(i) ₂ _(,2) and s′_(i) ₁ _(,1)

s′_(i) ₂ _(,1)

s′_(i) ₀ _(,1), based on the determining, including the second set ofpairs in the function semilattice canonical form.
 3. The one or moretangible non-transitory computer-readable storage media of claim 1,further comprising instructions for: accepting an s′ as input, wheres′=<<s′_(i2), s′_(i1)>>_(i=1, . . . k), each s′_(ij) being an element ofS_(j) for i=1, . . . , k and j=1 or 2; applying a function semilatticereduction algorithm to s′ to obtain an element of S.
 4. The one or moretangible non-transitory computer-readable storage media of claim 3,wherein the function semilattice reduction algorithm comprisesinstructions for: accepting an s′ as input, where s′=<<s′_(i2),s′_(i1)>>_(i=1, . . . k), each s′_(ij) being an element of S_(j) fori=1, . . . , k and j=1 and 2; repeating until neither of the followingcan be performed: if a non-minimal element of s′ exists, then deletingthe non-minimal element from s′, or if there exists i₁ and i₂ in a rangefrom 1 to k such that s′_(i) ₁ _(,1)

s′_(i) ₂ _(,1)≠⊥ and there does not exist i₀ in the range from 1 to ksuch that s′_(i) ₀ _(,2)

s′_(i) ₁ _(,2)

s′_(i) ₂ _(,2) and s′_(i) ₁ _(,1)

s′_(i) ₂ _(,1)

s′_(i) ₀ _(,1), then adding <s′_(i) ₁ _(,2)

s′_(i) ₂ _(,2), s′_(i) ₁ _(,1)

s′_(i) ₂ _(,1)> to s′; and yielding the current value of s′.
 5. The oneor more tangible non-transitory computer-readable storage media of claim3, further comprising instructions for: accepting an s₁ and s₂ as input,where s₁ and s₂ are elements of the function semilattice S oversemilattices S₁ and S₂; and calculating a greatest lower bound for s₁and s₂ using the greatest lower bound operations of S₁ and S₂.
 6. Theone or more tangible non-transitory computer-readable storage media ofclaim 5, wherein the greatest lower bound operation comprisesinstructions for: accepting an s₁ and s₂ as input, where s₁ and s₂ areelements of the function semilattice S over semilattices S₁ and S₂,represented as elements in function semilattice canonical form; andapplying the function semilattice reduction algorithm to a set union ofs₁ and s₂.
 7. The one or more tangible non-transitory computer-readablestorage media of claim 1, further comprising instructions for: providingelement s₁ and element s₂ in function semilattice canonical form;calculating whether element s₁ is less than or equal to element s₂ bythe condition that for every <s₂₂, s₂₁> there must exist <s₁₂, s₁₁> suchthat s₁₂ is less than or equal to s₂₂ and s₁₁ is less than or equal tos₂₁.
 8. The one or more tangible non-transitory computer-readablestorage media of claim 1, where in the algorithm for the partialordering further comprises instructions for: accepting an s₁ and s₂ asinput, where s_(h)=<<s_(hi2), s_(hi1)>>_(i=1, . . . , k) _(h) , eachs_(hij) being an element of S_(j) for h=1 and 2, i=1, . . . , k_(h), andj=1 and 2, a partial ordering on S_(j) denoted

_(j); calculating s₁

s₂ as a condition that for every i₂ in a range 1, . . . , k₂, thereexists i₁ in the range 1, . . . , k₂ such that r_(1,i) ₁ _(,2)

₂r_(2,i) ₂ _(,2) and r_(2,i) ₂ _(,1)

₁r_(1,i) ₁ _(,1).